import java.util.*;
import java.io.*;

class UserDatabaseTestDriver {
	public static void main(String[] args) {

		UserDatabase usrDb = new UserDatabase();

		System.out.println("User Database, constructor done..");

		StudentCourseTable stuCrseDb = new StudentCourseTable(usrDb);
		CourseDatabase crseDb = new CourseDatabase();

		String[] crsesAv = crseDb.getAllCourseIds();
		int nCoursesAv = crseDb.numberOfCourses();


		System.out.println("Student Course Table constructor done...");

		String [] stuIds = usrDb.GetAllStudentsbyId();
		int nStudents = usrDb.NumberOfStudents();

		System.out.println("Students in dB: ");
		for (int n = 0; n < nStudents ; n++) {
			System.out.println(stuIds[n]);
		}

		System.out.println("courses available: ");
		for (int n = 0; n < nCoursesAv ; n++) {
			System.out.println(crsesAv[n]) ;
		}
/*
		System.out.println("Registering Students..");
		for (int n = 0; n < nStudents ; n++) {
			if (stuCrseDb.RegisterStudentToCourse(usrDb, stuIds[n], crsesAv[3])) {
				System.out.println("Registered Student: " + stuIds[n] + " To course: " + crsesAv[3]);
				System.out.println("......Students CourseLog: " + stuCrseDb.GetStudentsCourseLog(stuIds[n]));
			}
			else
			{
				System.out.println("Registration failed for Student: " + stuIds[n] + " To course: " + crsesAv[0]);
			}
		}


		System.out.println("Registering  Students.. to course already Regd.  SHOULD FAIL!" + crsesAv[0]);
		for (int n = 0; n < nStudents ; n++) {
			if (stuCrseDb.RegisterStudentToCourse(usrDb, stuIds[n], crsesAv[0])) {
				System.out.println("egistered Student: " + stuIds[n] + " To course: " + crsesAv[0]);
				System.out.println("......Students CourseLog: " + stuCrseDb.GetStudentsCourseLog(stuIds[n]));
			}
			else
			{
				System.out.println("Registration failed for Student: " + stuIds[n] + " To course: " + crsesAv[0]);
			}
		}

		System.out.println("UnRegistering  Students.. from course" + crsesAv[0]);
		for (int n = 0; n < nStudents ; n++) {
			if (stuCrseDb.DropCourseForStudent(usrDb, stuIds[n], crsesAv[0])) {
				System.out.println("Un-Registered Student: " + stuIds[n] + " To course: " + crsesAv[0]);
				System.out.println("......Students CourseLog: " + stuCrseDb.GetStudentsCourseLog(stuIds[n]));
			}
			else
			{
				System.out.println("Un-Registration failed for Student: " + stuIds[n] + " To course: " + crsesAv[0]);
			}
		}
*/
		Student aStudent = usrDb.GetStudent(stuIds[0]);
		System.out.println("Current Student: ");
		System.out.println(aStudent.toString());

		// supose user changes these 3 fields
		aStudent.setAddress2(new String("Apt 105"));
		aStudent.setCity(new String("Boise"));
		aStudent.setEmail(new String("newEmail@newDomain.com"));

		StudentTableIndices[] enFieldsChanged = new StudentTableIndices[3];

		enFieldsChanged[0] = StudentTableIndices.enIndxStudentAddrs2;
		enFieldsChanged[1] = StudentTableIndices.enIndxStudentAddrsCity;
		enFieldsChanged[2] = StudentTableIndices.enIndxStudentEmail;

		usrDb.UpdateStudent(aStudent, enFieldsChanged, 3);

		System.out.println("Changed student: ");
		System.out.println(aStudent.toString());


		stuCrseDb.CloseDatabase();
		usrDb.CloseDatabase();
	}
}
